<!--
 * @Descripttion:
 * @version:
 * @Author: sueRimn
 * @Date: 2020-11-14 14:16:34
 * @LastEditors: sueRimn
 * @LastEditTime: 2020-11-18 14:45:29
-->
<template>
  <div class="app-container">
    <!-- //查询条件 -->
    <div class="search">
      <div class="search_left">
        <el-form :inline="true" :model="searchForm" class="demo-form-inline">
          <el-form-item label="视频标题">
            <el-input v-model="searchForm.title" placeholder="请输入名称" />
          </el-form-item>
          <el-form-item label="上传用户">
            <el-input v-model="searchForm.nicheng" type="tel" placeholder="请输入名称" />
          </el-form-item>
          <el-form-item label="日期范围">
            <el-date-picker
              v-model="timeValue1"
              type="daterange"
              range-separator="至"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
              @change="dateChange"
            />
          </el-form-item>
        </el-form>
      </div>
      <div class="search_right">
        <el-button type="primary" @click="get_ListData">查询</el-button>
        <el-button type="info" @click="reset">重置</el-button>
      </div>
    </div>
    <!-- 操作条件 -->
    <div class="btnGround">
      <!-- <div>
        <el-radio-group v-model="searchForm.is_check" @change="radioChang">
          <el-radio-button :label="1">待人工审核</el-radio-button>
          <el-radio-button :label="2">审核通过</el-radio-button>
        </el-radio-group>
      </div> -->
      <!-- <div>
        <el-button type="primary">新增机构</el-button>
        <el-button type="danger">批量删除</el-button>
      </div> -->
    </div>
    <!-- 表格 -->
    <el-table
      v-loading="listLoading"
      :data="list"
      element-loading-text="Loading"
      border
      fit
      highlight-current-row
      @selection-change="handleSelectionChange"
    >
      <!-- //多选选项 -->
      <el-table-column
        type="selection"
        width="55"
      />
      <el-table-column
        width="50"
        label="序号"
        align="center"
      >
        <template slot-scope="scope">
          {{ scope.$index + 1 + pageSize*(currentPage - 1 ) }}
        </template>
      </el-table-column>
      <el-table-column label="文章标题" header-align="center" prop="title" />
      <el-table-column label="上传用户" align="center" width="100px">
        <template slot-scope="scope">
          {{ scope.row.nicheng == '' ? '暂无' : scope.row.nicheng }}
        </template>
      </el-table-column>
      <el-table-column label="话题" align="center" prop="topic_name" width="100px">
        <template slot-scope="scope">
          {{ scope.row.topic_name == null ? '无' : scope.row.topic_name }}
        </template>
      </el-table-column>
      <el-table-column label="点赞" align="center" prop="likenum" sortable width="100px" />
      <el-table-column label="评论" align="center" prop="commentnum" sortable width="100px" />
      <el-table-column label="转发" align="center" prop="transpondnum" sortable width="100px" />
      <el-table-column label="不喜欢" align="center" prop="dislikenum" sortable width="100px" />
      <el-table-column label="类型" align="center" prop="type" width="100px">
        <template slot-scope="scope">
          {{ scope.row.type == '1' ? '普通模式' : 'PK模式' }}
        </template>
      </el-table-column>
      <el-table-column label="发布时间" align="center" prop="creat_time" sortable width="200px">
        <template slot-scope="scope">
          {{ scope.row.update_time * 1000 | get_YMDHMS }}
        </template>
      </el-table-column>
      <el-table-column
        fixed="right"
        label="操作"
        width="300"
        align="center"
      >
        <template slot-scope="scope">
          <el-button size="mini" type="primary" icon="el-icon-search" @click="to_VideoDetails(scope.row)">查看</el-button>
          <el-button size="mini" type="success" @click="to_examine(scope.row)">审核</el-button>
          <el-button size="mini" type="danger" @click="to_back(scope.row)">退回</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- //分页 -->
    <div class="bottomPagination">
      <el-pagination
        :current-page="currentPage"
        :page-sizes="[10,30,50]"
        :page-size="pageSize"
        layout=" sizes, prev, pager, next,total, jumper"
        :total="total"
        @current-change="handleCurrentChange"
        @size-change="handleSizeChange"
      />
    </div>
    <!-- //查看视频 -->
    <el-dialog title="查看视频" :visible.sync="dialogVideoVisible" width="700px">
      <div class="lookVideo">
        <video
          id="my-video"
          :src="showVideoUrl"
          controls=""
          style="width:600px;height:300px"
        />
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogVideoVisible = false">取 消</el-button>
        <el-button type="primary" @click="dialogVideoVisible = false">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { get_Video } from '@/api/trembleSchool/video'
import { check_Article } from '@/api/trembleSchool/article'
import { formatDate } from '@/utils/getTime'
export default {
    filters: {
        get_YMDHMS: function(value) {
            if (!value) return ''
            value = formatDate(value)
            return value
        }
    },
    data() {
        return {
            // 属性命名要与查询属性一致
            searchForm: {
                title: '',
                nicheng: '',
                is_check: 1,
                start_time: '',
                end_time: ''
            },
            list: [], // 表格数据
            currentPage: 1, // 页数
            total: 0, // 总数
            pageSize: 10, // 每页条数
            listLoading: false, // table 加载
            multipleSelection: [], // 多选

            timeValue1: '',
            dialogVideoVisible: false,
            showVideoUrl: '' // 视频查看

        }
    },
    created() {
        // 初始化表格
        this.get_ListData()
    },
    methods: {
        // 获取列表数据
        async get_ListData() {
            this.listLoading = true
            var queryData = {
                pagesize: this.pageSize,
                page: this.currentPage
            }
            var searchObj = this.searchForm
            // 自动添加查询条件
            for (let key in searchObj) {
                if (searchObj[key]) {
                    queryData[key] = searchObj[key]
                }
            }
            var data = await get_Video(queryData)
            console.log('视频列表：', data)
            if (data.code == 200) {
                this.list = data.data.data
                this.total = data.data.total
            } else {
                this.list = []
            }
            this.listLoading = false
        },
        // 条件重置
        reset() {
            // 属性命名要与查询属性一致
            this.searchForm = {
                title: '',
                nicheng: '',
                is_check: 1,
                start_time: '',
                end_time: ''
            }
            this.currentPage = 1
            this.get_ListData()
        },
        handleSelectionChange(val) {
            this.multipleSelection = val
            console.log(this.multipleSelection)
        },
        handleCurrentChange(val) {
            this.currentPage = val
            this.get_ListData()
        },
        handleSizeChange(val) {
            this.currentPage = 1
            this.pageSize = val
            this.get_ListData()
        },
        dateChange() {
            if (this.timeValue1.length == 0) {
                this.searchForm.start_time = ''
                this.searchForm.end_time = ''
                return
            }
            this.searchForm.start_time = (new Date(this.timeValue1[0]).getTime()) / 1000
            this.searchForm.end_time = (new Date(this.timeValue1[1]).getTime()) / 1000
        },
        radioChang() {
            this.get_ListData()
        },
        to_VideoDetails(row) {
            console.log('查看视频：', row)
            this.showVideoUrl = row.video_url
            this.dialogVideoVisible = true
        },
        async to_examine(row) {
            var queryData = {
                is_check: 2,
                article_video_id: row.video_id,
                content_type: 2
            }
            var data = await check_Article(queryData)
            console.log('审核视频：', data)
            if (data.code == 200) {
                this.$message({
                    type: 'success',
                    customClass: 'customClass',
                    message: '审核通过!'
                })
                this.get_ListData()
            }
        },
        to_back(row) {
            this.$prompt('请输入违规原因', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消'
            }).then(async({ value }) => {
                var queryData = {
                    is_check: 3,
                    article_video_id: row.video_id,
                    content_type: 2,
                    content: value
                }
                var data = await check_Article(queryData)
                console.log('审核视频：', data)
                if (data.code == 200) {
                    this.$message({
                        type: 'success',
                        customClass: 'customClass',
                        message: '操作通过!'
                    })
                    this.get_ListData()
                }
            }).catch(() => {})
        }
    }
}
</script>

<style scoped lang='scss'>
.search{
    display: flex;
    justify-content:space-between;
    align-items: center;
    flex-wrap: wrap;
    width: 100%;
    .search_left{
        display: flex;
        align-items: center;
        .el-form-item{
            margin-bottom: 0 !important;
        }
    }
    .search_right{}
}

.btnGround {
    width: 100%;
    display: flex;
    flex-wrap: wrap;
    // flex-direction: row-reverse;
    justify-content: space-between;
    margin: 30px 0 15px 0;
}

.bottomPagination {
    padding: 15px 0;
}

.lookVideo {
    width: 100%;
    display: flex;
    justify-content: center;
}
</style>
